package com.weipt.method;

/**
 * @author peter.wei 2020/10/09 10:05
 * @version 1.0
 * @company 终生学习
 * @description <br>peter.wei 2020/10/09 10:05
 * 和简单工厂模式中工厂负责生产所有产品相比，工厂方法模式将生成具体产品的任务分发给具体的产品工厂
 **/
public class PhoneFactory {
    public static void main(String[] args) {
        AbstractFactory huaweiFactory = new HuaweiFactory();
        AbstractFactory xiaomiFactory = new MiFactory();
        huaweiFactory.makePhone();
        xiaomiFactory.makePhone();
    }
}

interface Phone {
    void make();
}

class MiPhone implements Phone {
    public MiPhone(){
        this.make();
    }

    public void make(){
        System.out.println("make xiaomi phone");
    }
}

class HuaweiPhone implements Phone {
    public HuaweiPhone(){
        this.make();
    }

    public void make(){
        System.out.println("make huawei phone");
    }
}

interface AbstractFactory{
    Phone makePhone();
}

class MiFactory implements AbstractFactory{

    @Override
    public Phone makePhone() {
        return new MiPhone();
    }
}

class HuaweiFactory implements AbstractFactory{

    @Override
    public Phone makePhone() {
        return new HuaweiPhone();
    }
}